{include file="top.html"}
<link rel="stylesheet" href="{$CSS_PATH}detail.css"/>
<script type="text/javascript" src="{$JS_PATH}jquery.cookie.js"></script>

<div class="wrapper clearfix">
    <div class="container">
        <div class="detail">
            <div class="detail-left">
                <img src="{$goods.goods_img}" alt="" title=""/>
            </div>
            <div class="detail-right">
                <h1 class="pro-title ">{$goods.goods_name}</h1>

                <div class="clearfix ">
                    <span class="feture-item" data-summary="学习规划一目了然，学习、练习、测试高度结合、完整的教学过程带来更好的学习效果！" data-feature="null"
                          original-title="">系统化学习</span>
                    <span class="feture-item" data-summary="课后作业专人批改，学习效果全掌握！" data-feature="null" original-title="">作业批改</span>
                    <span class="feture-item" data-summary="课后作业专人批改，学习效果全掌握！" data-feature="null" original-title="">  在线一对一  </span>
                    <span class="feture-item" data-summary="提供独家学习资料或内部讲义下载，辅助课程学习，达成最终学习目标！" data-feature="null"
                          original-title="">名师答疑</span>

                </div>
                <div class="clearfix detail-price">
                    <p>
                        <input id="shop-price" type="hidden" value="{$goods.shop_price}"/>
                        <span class="class-price-unit">￥</span><span class="class-price" id="sum-price">{$goods.shop_price}</span>
                        <!--<span class="class-price-unit">~ ￥</span> <span class="class-price" >{$goods.market_price}</span>-->
                        促销活动简短说明
                    </p>
                </div>

                <script type="text/javascript" src="//cdn.bootcss.com/jquery.tipsy/1.0.2/jquery.tipsy.js"></script>

                <script type="text/javascript">
                    $( ".feture-item" ).tipsy( {
                        gravity : 's',
                        fade    : true,
                        title   : function() {
                            return this.getAttribute( 'data-summary' );
                        },
                        opacity : 1,
                        delayIn : 0,
                        delayOut: 0
                    } );
                </script>
                <div class="clearfix detail-panel" id="attrs">
                    {foreach from=$specification item=spec key=spec_key}

                    <dl>
                        <dt class="_attr-key" data-attr-id="{$spec_key}">{$spec.name}：</dt>
                        {foreach from=$spec.values item=value key=key}
                        <dd class="_property">
                            <a class="_attr-val" data-goods-id="{if $value.goods_id neq ''}{$value.goods_id}{else}{/if}" data-value-id="{$value.id}" data-url="{$value.tag}"
                               data-price="{if $value.price neq ''}{$value.price}{else}{/if}">{$value.label}</a>
                        </dd>
                        {/foreach}
                    </dl>
                    {/foreach}

                </div>
                <div class="btns-box clearfix">
                    <a href="javascript:void(0);" class="btnBuy2 htevent" target="_blank" id="makeOrder">立即购买</a>
                    <a target="_blank" href="http://www10.53kf.com/webCompany.php?arg=10069074&style=1&keyword=&kf="
                       class="btnConsult htevent">课程咨询</a>
                </div>
            </div>
        </div>
        <div class="good-detail clearfix">
            <p>
                <img src="/images/pc/detail_02.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_03.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_04.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_05.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_06.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_07.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_08.jpg" alt="" title="">
            </p>

            <p>
                <img src="/images/pc/detail_09.jpg" alt="" title="">
            </p>

        </div>
    </div>

    <script>
        $( function() {
        if( '{$selected}' != '' ) {
            var item_attrs = $.parseJSON( '{$selected}' );
        }
        else {
            var item_attrs = {};
        }
            var key='key={$smarty.get.key}&';
        var attr_url = '';
        var goods_id='{$goods.goods_id}';
            //var goods_attr_id=$( '#attrs .active' ).last().find('a' ).attr('data-value-id');

        //console.info( goods_attr_id );
        $( '._attr-val' ).each( function() {

            for( var i in item_attrs ) {
                if( item_attrs[ i ] == $( this ).text() ) {
                    if(i==2){
                        //$( "#sum-price" ).text( $(this ).attr( "data-price" ) );
                        //goods_id=$(this ).attr('data-goods-id');
                    }else{
                        /*if($( "#sum-price" ).text()=='')
                        {
                            $( "#sum-price" ).text( 0.00 );
                        }*/
                    }
                    $( this ).parents( '._property ' ).addClass( 'active' )
                }
            }

        } )

            //console.info(goods_attr_id)

        $( "._property" ).click( function() {
            var price = $( this ).find( 'a' ).attr( "data-price" );
            attr_url = $( this ).find( 'a' ).attr( 'data-url' );
            if( price != '' ) {
                $( "#sum-price" ).text( price )
                goods_id=$(this ).find('a' ).attr('data-goods-id');
            }
            var attr_id = $( this ).siblings( '._attr-key' ).attr( 'data-attr-id' );
            var attr_value = $( this ).find( 'a' ).text();
            if( attr_id == 2 ) {
                item_attrs[ attr_id ] = $( this ).find( 'a' ).attr( 'data-value-id' );
            }
            else {
                item_attrs[ attr_id ] = attr_value;
            }

            if( $( this ).hasClass( 'active' ) ) {
                delete item_attrs[ attr_id ];
                $( this ).removeClass( 'active' );
            }
            else {
                $( this ).addClass( 'active' ).siblings( 'dd' ).removeClass( 'active' );
            }
            goods_attr_id=$( '._attr-val' ).last().attr('data-attr-id');
            selectAttr();
        } )
            function getLastAttrId()
            {
                var tt='';
                $("._property" ).each(function(){
                    if($(this ).hasClass('active'))
                    {
                        tt=$(this ).find('a' ).attr('data-value-id');
                    }
                });
                return tt;
            }
        /*$("._property" ).click(function(){
         var attr_id=$(this ).siblings('._attr-key').attr('data-attr-id');
         var val_id=$(this ).find('a' ).attr('data-value-id');
         item_attrs[attr_id]=val_id;
         if($(this ).hasClass('active')){
         delete item_attrs[attr_id];
         $(this).removeClass('active');
         }else{
         $(this ).addClass('active' ).siblings('dd' ).removeClass('active');
         }
         if($(this ).find('a' ).text()=='上纽大直通车'&&$(this ).hasClass('active'))
         {
         $('._property' ).each(function(){

         if($(this ).find('a' ).text()=='高三'){
         var _temp_attr_id=$(this ).siblings('._attr-key').attr('data-attr-id');
         console.info(_temp_attr_id);
         delete item_attrs[_temp_attr_id];
         $(this ).removeClass('active').hide();
         }
         })
         }else{
         $('._property' ).each(function(){
         $(this ).show();
         })
         }
         console.info(item_attrs);
         //selectAttr();
         })*/
        function selectAttr() {
            $.post( '?act=add_goods_attr', { item_attrs: item_attrs }, function( data ) {
                console.info( data );
                window.location.href='?'+key+attr_url;
            } )
        }
console.info(item_attrs);
        $( "#makeOrder" ).click( function() {
            console.info(item_attrs[0])
            console.info(item_attrs[1]);
            console.info(item_attrs[2]);
            //return ;
            if(typeof item_attrs[0]=="undefined"||item_attrs[0]==''||item_attrs[0]==null){
                return alert('请先选择学习方法')
            }
            if(typeof item_attrs[1]=="undefined"||item_attrs[1]==''||item_attrs[1]==null)
            {
                return alert('请先选择年级');
            }
            if(typeof item_attrs[2]=="undefined"||item_attrs[2]==''||item_attrs[2]==null){
                return alert('请先选择课时');
            }
            $.post( 'user.php?act=add_order', { goods_id: goods_id }, function( data ) {
                console.info( data );
                //return ;
                if( data.status == 'false' && data.type == 'no_login' ) {
                    return login();
                }
                var order_id = data.data;
                window.location.href = 'user.php?act=confirm_order&goods_id=' + goods_id+'&goods_attr_id='+getLastAttrId();
            }, 'json' );
        } )
        })
    </script>


</div>

{include file="foot.html"}
</body>
</html>